﻿#include"RBTree.hpp"

template<class K>
class set
{
private:
	typedef RBTree<K, size_t> Container;
	typedef typename Container::Node Node;
public:
	typedef typename Container::iterator iterator;
	typedef typename Container::const_iterator const_iterator;
public:
	set()
	{}

	~set()
	{}

	iterator begin()
	{
		return _con.begin();
	}

	iterator end()
	{
		return _con.end();
	}

	const_iterator cbegin()
	{
		return _con.cbegin();
	}

	const_iterator cend()
	{
		return _con.cend();
	}

	pair<iterator,bool> insert(const K& key)
	{
		Node* tmp = _con.find(key);
		if (tmp)
		{
			tmp->_val++;
			return make_pair(iterator(tmp), false);
		}
		else
		{
			_con.insert(key, 1);
			Node* tmp = _con.find(key);
			return make_pair(iterator(tmp), true);
		}
	}

	iterator find(const K& key)
	{
		Node* tmp = _con.find(key);
		return iterator(tmp);
	}

	size_t size()
	{
		return _con.size();
	}

	bool empty()
	{
		return _con.empty();
	}

	size_t count(const K& key)
	{
		Node* tmp = find(key);
		if (!tmp)
		{
			return 0;
		}
		else
		{
			return tmp->_val;
		}
	}


private:
	Container _con;
};